<template>
	<view>
		<view class="login-box" style="background: url(https://hyjd-ycyjydt.com/emergency-study-web/login.png) no-repeat; background-size: 100% 100%;">
			<view class="logo-input">
				<u-input v-model="subject" type="type" :custom-style="customStyleInput" placeholder="请输入员工号或者手机号" />
				<view class="input-view"></view>
				<u-input v-model="credential" type="password" :custom-style="customStyleInput" placeholder="请输入密码" right-icon="eye" />
				<view class="input-view"></view>
				<u-row gutter="16" justify="around">
					<u-col span="6">
						<u-button type="primary" :custom-style="customStyleButton1" hover-class="none" @click="loginButton('GUEST')">我是游客，不登录</u-button>
					</u-col>
					<u-col span="6">
						<u-button type="primary" :custom-style="customStyleButton" hover-class="none" @click="loginButton('USERNAME')">登录</u-button>
					</u-col>
				</u-row>
				<view class="input-view" style="height: 100rpx; line-height: 100rpx;">
					还没有账号？<text style="color: #F18B3A;" @click="registered">立即注册</text>
				</view>
			</view>
		</view>
		<view class="name">
			延长油田股份有限公司
		</view>
	</view>
</template>

<script>
	import {login} from '../../api/api.js'
	export default {
		data() {
			return {
				subject:'',
				credential:'',
				code:'',
				customStyleInput:{
					backgroundColor:'#FAFBFF',
					paddingLeft: '20rpx',
					borderRadius: '12rpx',
					height: '88rpx'
				},
				customStyleButton:{
					backgroundColor:'#F18B3A',
					borderRadius: '12rpx',
					height: '88rpx',
					border:'solid 1rpx #F18B3A'
				},
				customStyleButton1:{
					border:'solid 1rpx #F18B3A',
					backgroundColor:'#FFF',
					borderRadius: '12rpx',
					height: '88rpx',
					color:'#F18B3A'
				}
			}
		},
		onShow() {
			this.getCode()
		},
		onLoad(query) {
			if(query.employeeNumber){
				this.subject = query.employeeNumber
			}
			if(query.pwd){
				this.credential = query.pwd
			}
		},
		mounted() {
			
		},
		methods: {
			// 获取code
			getCode(){
				let self = this
				uni.login({
					success(resp) {
						self.code = resp.code
					}
				})
			},
			// 登录
			loginButton(type){
				let parmes = {
					subject:this.subject,
					credential:this.credential,
					// code: this.code,
					type: type
				}
				login(parmes).then(resp=>{
					uni.setStorageSync('userObj',resp)
					uni.setStorageSync('access_token',resp.token)
					uni.switchTab({
						url:"/pages/index/index"
					})
				})
				this.getCode()
			},
			// 注册
			registered(){
				uni.navigateTo({
					url:"../registered/registered"
				})
			},
			sao(){
				uni.scanCode({
					success:function(res){
						
					},
					fail:function(res){
						uni.switchTab({
							url:'/pages/page/page'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.name{
	position: fixed;
	width: 100%;
	height: 50rpx;
	line-height: 50rpx;
	color: #000;
	text-align: center;
	z-index: 99;
	left: 0;
	bottom: 30rpx;
}
.login-box{
	padding: 0 60rpx;
	height: 100vh;
	.logo{
		margin-top: 100rpx;
		width: 400rpx;
		height: 100rpx;
		text-align: center;
		line-height: 100rpx;
	}
	.logo-title{
		margin-top: 44rpx;
		width: 300rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
	}
	.logo-input{
		padding-top:550rpx;
		margin-bottom: 50rpx;
		.input-view{
			height: 20rpx;
			text-align: center;
		}
	}
	.logo-pic{
		text-align: center;
		width: 100%;
		.logo-sao{
			margin: 0 auto 10rpx;
			width: 108rpx;
			height: 108rpx;
			background-color: red;
			border-radius: 50%;
		}
	}
}
</style>
